package com.neusoft.yiyang.care.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.neusoft.yiyang.common.entity.care.CareItem;
import com.neusoft.yiyang.care.service.CareItemService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "护理项目管理接口", description = "负责护理项目的增删改查及分页查询")
@RestController
@RequestMapping("/care-items")
public class CareItemController {

    @Autowired
    private CareItemService careItemService;

    @Operation(summary = "获取所有护理项目", description = "查询系统中所有的护理项目信息")
    @GetMapping("/all")
    public List<CareItem> getAllCareItems() {
        return careItemService.getAllCareItems();
    }

    @Operation(summary = "根据ID获取护理项目", description = "通过护理项目ID查询具体的项目详情")
    @GetMapping("/{careItemId}")
    public CareItem getCareItemById(
            @Parameter(description = "护理项目ID", required = true) @PathVariable Integer careItemId) {
        return careItemService.getCareItemById(careItemId);
    }

    @Operation(summary = "添加新的护理项目", description = "新增护理项目信息（包含名称、价格、周期等）")
    @PostMapping("/add")
    public void addCareItem(
            @Parameter(description = "护理项目信息", required = true) @RequestBody CareItem careItem) {
        careItemService.addCareItem(careItem);
    }

    @Operation(summary = "更新护理项目", description = "根据ID修改护理项目的信息")
    @PutMapping("/{careItemId}")
    public void updateCareItem(
            @Parameter(description = "护理项目ID", required = true) @PathVariable Integer careItemId,
            @Parameter(description = "更新后的护理项目信息", required = true) @RequestBody CareItem careItem) {
        careItem.setCareItemId(careItemId);
        careItemService.updateCareItem(careItem);
    }

    @Operation(summary = "删除护理项目", description = "根据ID删除指定的护理项目")
    @DeleteMapping("/{careItemId}")
    public void deleteCareItem(
            @Parameter(description = "护理项目ID", required = true) @PathVariable Integer careItemId) {
        careItemService.deleteCareItem(careItemId);
    }

    @Operation(summary = "分页查询护理项目", description = "支持按状态和名称筛选，返回分页后的护理项目列表")
    @GetMapping("/page")
    public Page<CareItem> pageQuery(
            @Parameter(description = "当前页码，默认1") @RequestParam(defaultValue = "1") Integer pageNum,
            @Parameter(description = "每页条数，默认10") @RequestParam(defaultValue = "10") Integer pageSize,
            @Parameter(description = "状态筛选（可选）") @RequestParam(required = false) String status,
            @Parameter(description = "名称筛选（可选，支持模糊匹配）") @RequestParam(required = false) String name
    ) {
        Page<CareItem> page = new Page<>(pageNum, pageSize);
        return careItemService.pageQuery(page, status, name);
    }
}